#include "RevelEncoder.h"
#include "revelluabindings.h"
#include "../core/LuaUtils.h"
#include "../core/SimpleImage.h"


void RevelBindings::pushStaticFuncs(lua_State* L)
{
	static const struct luaL_Reg mylib [] = {
		{"StartEncoding", li_startEncoding},
		{"FinalizeEncoding", li_finalizeEncoding},
		{"EncodeFrame", li_encodeFrame},
		{NULL, NULL}  /* sentinel */
	};

	// dump them into said table
	luaL_register(L, NULL, mylib);
}

int RevelBindings::li_startEncoding(lua_State* L)
{
	RevelEncoder* op = (RevelEncoder*)typeCheckUnboxAO(L,1,"RevelEncoder");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	int a1 = (int)lua_tointeger(L, 2);
	int a2 = (int)lua_tointeger(L, 3);
	float a3 = (float)lua_tonumber(L, 4);
	float a4 = (float)lua_tonumber(L, 5);
	std::string a5 = getSafeLuaString(L, 6);
	op->startEncoding(a1, a2, a3, a4, a5);
	
	return 0;
}


int RevelBindings::li_finalizeEncoding(lua_State* L)
{
	RevelEncoder* op = (RevelEncoder*)typeCheckUnboxAO(L,1,"RevelEncoder");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	op->finalizeEncoding();
	
	return 0;
}


int RevelBindings::li_encodeFrame(lua_State* L)
{
	RevelEncoder* op = (RevelEncoder*)typeCheckUnboxAO(L,1,"RevelEncoder");
	if(op == NULL){
		LOG(logERROR) << "Null self!";
	return 0;}
	SimpleImage* a1 = pop_custom<SimpleImage>(L, 2, "SimpleImage");
	op->encodeFrame(a1);
	
	return 0;
}


